<?xml version="1.0" encoding="UTF-8"?>

<!-- Copyright 2007 XBRL International. All Rights Reserved. -->

<link:linkbase
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:link="http://www.xbrl.org/2003/linkbase"
  xmlns:generic="http://xbrl.org/2008/generic"
  xmlns:formula="http://xbrl.org/2008/formula"
  xmlns:variable="http://xbrl.org/2008/variable"
  xmlns:cf="http://xbrl.org/2008/filter/concept"
  xmlns:tf="http://xbrl.org/2008/filter/tuple"
  xmlns:gf="http://xbrl.org/2008/filter/general"
  xmlns:pf="http://xbrl.org/2008/filter/period"

  xmlns:label="http://xbrl.org/2008/label"
  xmlns:xfi="http://www.xbrl.org/2008/function/instance" 
  xmlns:v="http://xbrl.org/2008/formula/conformance/variable"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:c="http://xbrl.org/formula/conformance/example"
  xmlns:gl-cor="http://www.xbrl.org/int/gl/cor/2006-10-25"

  xsi:schemaLocation="
  http://www.xbrl.org/2003/linkbase http://www.xbrl.org/2003/xbrl-linkbase-2003-12-31.xsd
  http://xbrl.org/2008/generic ../../core_schemas/generic-link.xsd
  http://xbrl.org/2008/formula ../../core_schemas/formula.xsd
  http://xbrl.org/2008/variable ../../core_schemas/variable.xsd
  http://xbrl.org/2008/filter/concept ../../core_schemas/concept-filter.xsd
  http://xbrl.org/2008/filter/period ../../core_schemas/period-filter.xsd
  http://xbrl.org/2008/filter/tuple ../../core_schemas/tuple-filter.xsd
  http://xbrl.org/2008/filter/general ../../core_schemas/general-filter.xsd
  http://xbrl.org/2008/label ../../core_schemas/generic-label.xsd
  ">
  
  <link:arcroleRef arcroleURI="http://xbrl.org/arcrole/2008/element-label" xlink:href="../../core_schemas/generic-label.xsd#element-label" xlink:type="simple"/>
  <link:arcroleRef arcroleURI="http://xbrl.org/arcrole/2008/variable-set" xlink:href="../../core_schemas/variable.xsd#variable-set" xlink:type="simple"/>
  <link:arcroleRef arcroleURI="http://xbrl.org/arcrole/2008/variable-filter" xlink:href="../../core_schemas/variable.xsd#variable-filter" xlink:type="simple"/>
  <link:arcroleRef arcroleURI="http://xbrl.org/arcrole/2008/variable-set-precondition" xlink:href="../../core_schemas/variable.xsd#variable-set-precondition" xlink:type="simple"/>

  <generic:link xlink:type="extended"
    xlink:role="http://www.xbrl.org/2003/role/link">

    <formula:formula xlink:type="resource" xlink:label="formula" 
      value="concat( 'Account ', $v:acctID, ' ending balance is ',
                (sum($v:creditAmts) - sum($v:debitAmts) ) )"
      source="v:qualifierBBF"
      aspectModel="non-dimensional" implicitFiltering="false">
      <formula:aspects>
        <formula:concept>
          <formula:qname>c:EndingBalance</formula:qname>
        </formula:concept>
      </formula:aspects>
    </formula:formula>


    <!--  Fact variables.  Note that no general variables are used in this formula. -->
    <variable:factVariable xlink:type="resource" xlink:label="variable_qualifierBBF"  bindAsSequence="false" />
    <variable:factVariable xlink:type="resource" xlink:label="variable_acctID"  bindAsSequence="false"/>
    <variable:factVariable xlink:type="resource" xlink:label="variable_creditAmounts" fallbackValue="()" bindAsSequence="true" />
    <variable:factVariable xlink:type="resource" xlink:label="variable_debitAmounts" fallbackValue="()" bindAsSequence="true" />

    <!--  Concept filters for the fact variables -->
    <cf:conceptName xlink:type="resource" xlink:label="filter_qualifier">
      <cf:concept>
        <cf:qname>gl-cor:qualifierEntry</cf:qname>
      </cf:concept>
    </cf:conceptName> 

    <cf:conceptName xlink:type="resource" xlink:label="filter_acctID">
      <cf:concept>
        <cf:qname>gl-cor:accountMainID</cf:qname>
      </cf:concept>
    </cf:conceptName> 

    <cf:conceptName xlink:type="resource" xlink:label="filter_amount">
      <cf:concept>
        <cf:qname>gl-cor:amount</cf:qname>
      </cf:concept>
    </cf:conceptName> 

    <!--  Tuple filters for the fact variables -->
    <tf:parentFilter xlink:type="resource" xlink:label="filter_qualifier">
        <tf:parent><tf:qname>gl-cor:entryHeader</tf:qname></tf:parent>
    </tf:parentFilter> 

    <tf:locationFilter xlink:type="resource" xlink:label="filter_acctID_tupleLocation"
      variable="v:qualifierBBF" 
      location="../../../gl-cor:qualifierEntry" />

    <!--  Ancestor filter to neutralize location on sequence subfiltering -->
    <tf:ancestorFilter xlink:type="resource" xlink:label="filter_anyLocation">
      <tf:ancestor><tf:qname>gl-cor:accountingEntries</tf:qname></tf:ancestor>
    </tf:ancestorFilter> 

    <!--  General filters for the fact variables -->
    <!--  Herm: special note on general filters:
                as they "fire" on each item and will produce type errors
                and are not dependent on conceptName filters, each has
                code to be sure it only tests when on the right concept.
                (See Wiki CR1 notes.)
    -->
    <gf:general xlink:type="resource" xlink:label="filter_acctID_not_ending_bal"
      test="
          if (local-name(.) ne 'accountMainID') then false() else
             ../../gl-cor:xbrlInfo/gl-cor:xbrlInclude ne 'ending_balance'
      "/>
    <gf:general xlink:type="resource" xlink:label="filter_amt_acctID" 
      test="
          if (local-name(.) ne 'amount') then false() else
             ../gl-cor:account/gl-cor:accountMainID eq $v:acctID
      "/>
    <gf:general xlink:type="resource" xlink:label="filter_codeC" 
      test="
          if (local-name(.) ne 'amount') then false() else
             ../gl-cor:debitCreditCode eq 'C'
        "/>
    <gf:general xlink:type="resource" xlink:label="filter_codeD" 
      test="
          if (local-name(.) ne 'amount') then false() else
             ../gl-cor:debitCreditCode eq 'D'
        "/>
    <gf:general xlink:type="resource" xlink:label="filter_amt_not_ending_bal" 
      test="
          if (local-name(.) ne 'amount') then false() else
             ../gl-cor:xbrlInfo/gl-cor:xbrlInclude ne 'ending_balance'
        "/>


    <!--  Value filters for the fact variables -->
    <gf:general xlink:type="resource" xlink:label="filter_BBF" 
      test="
          if (local-name(.) ne 'qualifierEntry') then false() else
             . eq 'balance-brought-forward'
        "/>

    <!--  Preconditions -->



    <!--  Labels for the formula and each variable -->
    <label:label xlink:type="resource" xlink:label="formula_label" 
      xlink:role="http://www.xbrl.org/2003/role/label" xml:lang="en">Tests the balance of a qualifier’s section of GL entry details.</label:label>
    <label:label xlink:type="resource" xlink:label="variable_qualifierBBF_label" 
      xlink:role="http://www.xbrl.org/2003/role/label" xml:lang="en">Binds to the qualifierEntry for BBF entryHeader </label:label>
    <label:label xlink:type="resource" xlink:label="variable_acctID_label" 
      xlink:role="http://www.xbrl.org/2003/role/label" xml:lang="en">Binds to each acctID in the BBF entryHeader</label:label>
    <label:label xlink:type="resource" xlink:label="variable_creditAmounts_label" 
      xlink:role="http://www.xbrl.org/2003/role/label" xml:lang="en">Sequence of qualifier’s “C”-sibling amts</label:label>    
    <label:label xlink:type="resource" xlink:label="variable_debitAmounts_label" 
      xlink:role="http://www.xbrl.org/2003/role/label" xml:lang="en">Sequence of qualifier’s “D”-sibling amts</label:label>    
   

    <!-- Arcs from labels to the formula and variables being labelled -->
    <generic:arc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/element-label"
      xlink:from="formula" xlink:to="formula_label" order="1.0"/>
    <generic:arc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/element-label"
      xlink:from="variable_qualifierBBF" xlink:to="variable_qualifierBBF_label" order="1.0"/>
    <generic:arc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/element-label"
      xlink:from="variable_acctID" xlink:to="variable_acctID_label" order="1.0"/>
    <generic:arc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/element-label"
      xlink:from="variable_creditAmounts" xlink:to="variable_creditAmounts_label" order="1.0"/>
    <generic:arc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/element-label"
      xlink:from="variable_debitAmounts" xlink:to="variable_debitAmounts_label" order="1.0"/>



    <!--  Arc from the formula to the variables it depends on -->
    <variable:variableArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-set" 
      xlink:from="formula" xlink:to="variable_qualifierBBF" order="1.0"
      name="v:qualifierBBF" />
    <variable:variableArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-set" 
      xlink:from="formula" xlink:to="variable_acctID" order="2.0"
      name="v:acctID" />
    <variable:variableArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-set" 
      xlink:from="formula" xlink:to="variable_creditAmounts" order="3.0"
      name="v:creditAmts" />
    <variable:variableArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-set" 
      xlink:from="formula" xlink:to="variable_debitAmounts" order="4.0"
      name="v:debitAmts" />

    <!--  Arcs from variables to their concept filters -->
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_qualifierBBF" xlink:to="filter_qualifier" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_qualifierBBF" xlink:to="filter_BBF" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_acctID" xlink:to="filter_acctID" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_acctID" xlink:to="filter_acctID_tupleLocation" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_acctID" xlink:to="filter_acctID_not_ending_bal" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_creditAmounts" xlink:to="filter_amount" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_creditAmounts" xlink:to="filter_amt_acctID" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_creditAmounts" xlink:to="filter_amt_not_ending_bal" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_creditAmounts" xlink:to="filter_codeC" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_creditAmounts" xlink:to="filter_anyLocation" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_debitAmounts" xlink:to="filter_amount" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_debitAmounts" xlink:to="filter_amt_acctID" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_debitAmounts" xlink:to="filter_amt_not_ending_bal" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_debitAmounts" xlink:to="filter_codeD" order="1.0"/>
    <variable:variableFilterArc xlink:type="arc" xlink:arcrole="http://xbrl.org/arcrole/2008/variable-filter" 
      complement="false" cover="true"
      xlink:from="variable_debitAmounts" xlink:to="filter_anyLocation" order="1.0"/>

    <!--  Arcs from formula to its precondition -->
  </generic:link>

</link:linkbase>
